namespace WpfClient.Shared.Extensions
{
    /// <summary>
    /// 字符串扩展方法
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// 检查字符串是否为空或null
        /// </summary>
        public static bool IsNullOrEmpty(this string? value)
        {
            return string.IsNullOrEmpty(value);
        }

        /// <summary>
        /// 检查字符串是否为空白或null
        /// </summary>
        public static bool IsNullOrWhiteSpace(this string? value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        /// <summary>
        /// 安全截取字符串
        /// </summary>
        public static string SafeSubstring(this string value, int startIndex, int length)
        {
            if (string.IsNullOrEmpty(value) || startIndex >= value.Length)
                return string.Empty;

            if (startIndex + length > value.Length)
                length = value.Length - startIndex;

            return value.Substring(startIndex, length);
        }
    }
}